#pragma once

// sResult ------------------------------------------------------


class eResultCode
{
public: 
	enum TYPE
	{
		FAIL = 0,
		OK,
		WARN,
		NOT_COMPLETE,
		EOE
	};
};


struct sResult
{
	sResult()
	{
		code = eResultCode::FAIL;
		value = 0;
	}

	sResult(eResultCode::TYPE code)
	{
		this->code = code;
		value = 0;
	}

	sResult(eResultCode::TYPE code, tInt value)
	{
		this->code = code;
		this->value = value;
	}

	sResult(eResultCode::TYPE code, tInt value, const tString& desc)
	{
		this->code = code;
		this->value = value;
		this->desc = desc;
	}

	sResult(eResultCode::TYPE code, const tString& desc)
	{
		this->code = code;
		value = 0;
		this->desc = desc;
	}

	sResult(eResultCode::TYPE code, const boost::format& desc)
	{
		this->code = code;
		value = 0;
		this->desc = desc.str();
	}

	sResult(eResultCode::TYPE code, tInt value, const boost::format& desc)
	{
		this->code = code;
		this->value = value;
		this->desc = desc.str();
	}

	sResult& operator = (const sResult& rhs)
	{
		this->code = rhs.code;
		this->value = rhs.value;
		this->desc = rhs.desc;
		return *this;
	}

	eResultCode::TYPE code;
	tInt value;
	tString desc;
};

inline tBool operator == (const sResult& rhs, eResultCode::TYPE code)
{
	return (rhs.code == code);
}

inline tBool operator != (const sResult& rhs, eResultCode::TYPE code)
{
	return (rhs.code != code);
}


#define RETURN_FAIL(RES) \
	if (RES.code == eResultCode::FAIL) \
{ \
	return ; \
}

#define RETURN_LOG(RES) \
{ \
	SPIRAL_LOG_ERROR(RES.desc); \
	return RES; \
}


#define RETURN_LOG_AND_FAIL(RES) \
	if (RES.code == eResultCode::FAIL) \
{ \
	SPIRAL_LOG_ERROR(RES.desc) \
	return RES; \
}




#define RETURN_FAIL_RESULT(RES) \
	if (RES.code == eResultCode::FAIL) \
{ \
	return RES; \
}


#define RETURN_AND_LOG_FAIL_RESULT(RES, LOG) \
	if (RES.code == eResultCode::FAIL) \
{ \
	SPIRAL_LOG_ERROR(LOG) \
	return RES; \
}

#define RETURN_VOID_AND_LOG_FAIL_RESULT(RES, LOG) \
	if (RES.code == eResultCode::FAIL) \
{ \
	SPIRAL_LOG_ERROR(LOG) \
	return; \
}

#define RETURN_FALSE_AND_LOG_FAIL_RESULT(RES, LOG) \
	if (RES.code == eResultCode::FAIL) \
{ \
	SPIRAL_LOG_ERROR(LOG) \
	return false; \
}


